SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.vw_PlazasAfectadasC
AS
SELECT pm.idCola,  p.CUPOF  AS CUPOF, 
    CASE f.regimensalarial WHEN 12 THEN NULL 
    ELSE SUM(sa.horas) END AS horas
FROM tb_PlazasdeMovimiento pm INNER JOIN
    tb_Subserviciosagentes ssa ON 
    pm.servicio = ssa.idsubservicio INNER JOIN
    tb_plazas p ON p.idplaza = ssa.plaza INNER JOIN
    tb_funciones f ON f.idfuncion = p.funcion INNER JOIN
    tb_serviciosagentes sa ON 
    sa.idservicioagente = ssa.servicioagente
INNER JOIN tb_ColaDeMovimientos cm on cm.idcola = pm.idcola
--WHERE sa.FechaAlta = ssa.FechaAlta
GROUP BY p.CUPOF, pm.idCola, f.regimensalarial






GO
GRANT SELECT ON  [dbo].[vw_PlazasAfectadasC] TO [SoloVer]
GO
